package com.oktest.measure.item.work.provider

import com.cali.common.kt.gone
import com.cali.common.kt.invisible
import com.cali.common.kt.visible
import com.chad.library.adapter.base.entity.node.BaseNode
import com.chad.library.adapter.base.provider.BaseNodeProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.oktest.measure.MyApp
import com.oktest.measure.R
import com.oktest.measure.entity.Measure
import kotlinx.android.synthetic.main.item_work_sub_02.view.*

/**
 * @Author hhh
 * @Date 2020/9/22
 *
 * 遥信
 */
class WorkSub2Provider : BaseNodeProvider() {
    override val itemViewType: Int = 4
    override val layoutId: Int = R.layout.item_work_sub_02

    override fun convert(helper: BaseViewHolder, remoteSign: BaseNode) {
        if (remoteSign !is Measure) return
        helper.itemView.apply {
            tvChanger.text = remoteSign.getValueDisplay()
            if (remoteSign.isSuccessful || !MyApp.taskIsReceived()) {
                sub2BoxCheck.invisible()
                etResult.isEnabled = false
            } else {
                sub2BoxCheck.visible()
                etResult.isEnabled = true
            }
            if (remoteSign.isSuccessful) {
                ivMark.visible()
                sub2BoxCheck.isChecked = false
            } else {
                ivMark.invisible()
                sub2BoxCheck.isChecked = remoteSign.isChecked
            }
            // 调测并失败
            if (remoteSign.isDebugging && !remoteSign.isSuccessful) {
                errorLayout.visible()
                tvErrorDesc.text = remoteSign.errorMsg
            } else {
                errorLayout.gone()
                tvErrorDesc.text = ""
            }
            etResult?.setText(remoteSign.value)
        }
    }

}